package com.bdqn.S64.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

//@Configuration
public class MySecurityUserConfig {
/*
    @Bean
    public UserDetailsService userDetailsService() {
        //创建2个用户,系统的用户
        UserDetails user1 = User.builder()
                .username("litianyu").
                        password(passwordEncoder()
                                .encode("123456"))
                //.roles("admin")           //角色,会变成权限
                //.authorities("admin")     //配置权限
                .authorities("admin:add","admin:update","admin:del")   //配置权限
                .build();  //谁在后面谁就生效

        UserDetails user2 = User.builder()
                .username("lixiyu").
                        password(passwordEncoder()
                                .encode("123456"))
                //.roles("student");  //ROLE_student
        .authorities("student:test").build();

        UserDetails user3 = User.builder()
                .username("lijiayu").
                        password(passwordEncoder()
                                .encode("123456"))
                //.roles("teacher");  //ROLE_teacher
        .authorities("teacher:test").build();
        InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
        manager.createUser(user1);
        manager.createUser(user2);
        manager.createUser(user3);
        return manager;
    }


    //密码加密器
    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }*/
}
